/**
 * parser - jQuery EasyUI
 * 
 * Licensed under the GPL terms
 * To use it on other terms please contact us
 *
 * Copyright(c) 2009-2012 stworthy [ stworthy@gmail.com ] 
 * 
 */

(function($) {
    $.parser = {
        auto: true,
        onComplete: function(context) {},
        plugins: ['linkbutton', 'menu', 'menubutton', 'splitbutton', 'progressbar', 'tree', 'combobox', 'combotree', 'numberbox', 'validatebox', 'searchbox', 'numberspinner', 'timespinner', 'calendar', 'datebox', 'datetimebox', 'slider', 'layout', 'panel', 'datagrid', 'propertygrid', 'treegrid', 'tabs', 'accordion', 'window', 'dialog'],
        parse: function(context) {
            var aa = [];
            for (var i = 0; i < $.parser.plugins.length; i++) {
                var name = $.parser.plugins[i];
                var tgt = $('.easyui-' + name, context);
                if (tgt.length) {
                    if (tgt[name]) {
                        tgt[name]();
                    } else {
                        aa.push({
                            name: name,
                            jq: tgt
                        });
                    }
                }
            }
            if (aa.length && window.easyloader) {
                var names = [];
                for (var i = 0; i < aa.length; i++) {
                    names.push(aa[i].name);
                }
                easyloader.load(names,
                function() {
                    for (var i = 0; i < aa.length; i++) {
                        var name = aa[i].name;
                        var jq = aa[i].jq;
                        jq[name]();
                    }
                    $.parser.onComplete.call($.parser, context);
                });
            } else {
                $.parser.onComplete.call($.parser, context);
            }
        }
    };
    $(function() {
        if (!window.easyloader && $.parser.auto) {
            $.parser.parse();
        }
    });
})(jQuery);